<#include "/ftl/lib/operations.ftl"/>
<div class="easyui-layout" fit="true">  
	<div region="north" style="padding:5px;border:1px solid #ddd; background-color: #f4f4f4" id="global_${action_id}"  >
	</div>  
	<div region="center" border="false">
		<div class="easyui-panel"  data-options="href:'${request.contextPath}${namespace?default('')}/agency/group-list.htm?action_id=${action_id}',fit:true">
		</div>
	</div>
</div>
<script type="text/javascript">

function add_${action_id}(){
	$('<div/>').dialog({
		href:'${request.contextPath}${namespace?default('')}/agency/group-form.htm?action_id=${action_id}',
		width:500,   
		height:400,   
		title: '新增',
		modal:true,
		maximizable:false,
		collapsible:false,
		minimizable:false,
		resizable:false,
		buttons:[{iconCls : 'icon-ok',
					text:'${action.getProperty('net.esj.background.message','bg.datagrid.save')}',
					handler:function(){
						var d = $(this).closest('.window-body');
						$('#form_${action_id}').form('submit', {
							url : '${request.contextPath}${namespace?default('')}/agency/group-add.json',
							onSubmit: function(){
								var nodes = $('#form_${action_id}').find('#funcTree').tree('getChecked');
								var ids = [] ;
								for(var i=0;i<nodes.length;i++){
									ids.push(nodes[i].id);
								}
								$('#form_${action_id}').find('[name="entity.funcsStr"]').val(ids.join(';'));
								return $(this).form('validate');
	        				},
							success : function(json) {
								eval("json="+json);
								$.messager.alert(json.title,json.msg,json.level);
								d.dialog('destroy');
								$("#datagrid_${action_id}").datagrid('reload');
							}
						});
					}}],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$('#form_${action_id}').find('#funcTree').tree({url:'${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=AT_AGENCY&model.id=AT_AGENCY&priority=1'});
		}
	});
}

function edit_${action_id}(data) {
	if(data.agencyG==0){
		$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/agency/group-edit.htm?action_id=${action_id}',
		width:500,   
		height:400,   
		modal : true,
		title : '查看',
		buttons : [ {
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#edit_${action_id}').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/agency/group-update.json',
					onSubmit: function(){
						var nodes = $('#edit_${action_id}').find('#funcTree').tree('getChecked');
						var ids = [] ;
						for(var i=0;i<nodes.length;i++){
							ids.push(nodes[i].id);
						}
						$('#edit_${action_id}').find('[name="entity.funcsStr"]').val(ids.join(';'));
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						d.dialog('destroy');
						$("#datagrid_${action_id}").datagrid('reload');
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$('#edit_${action_id}').find('#funcTree').tree({
				url:'${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=AT_AGENCY&model.id=AT_AGENCY&priority=1',
				onLoadSuccess:function(){
					$.get('${request.contextPath}${namespace?default('')}/agency/group-load.json?id='+data.id+'&n='+Math.random(),{},function(data){
						eval("data="+data);
						$('#edit_${action_id}').form('load',data);
						var funcs = data["entity.funcsStr"].split(';');
						for(var i = 0;i<funcs.length;i++){
							var node = $('#edit_${action_id}').find('#funcTree').tree('find',funcs[i]);
							if(node){
								$('#edit_${action_id}').find('#funcTree').tree('check',node.target);
							}
						}
					});
					}
				});
			}
		});
	}else{
		$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/agency/group-view.htm?action_id=${action_id}',
		width:500,   
		height:400,   
		modal : true,
		title : '查看',
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$('#view_${action_id}').find('#funcTree').tree({
				url:'${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=AT_AGENCY&model.id=AT_AGENCY&priority=1',
				onLoadSuccess:function(){
					$.get('${request.contextPath}${namespace?default('')}/agency/group-load.json?id='+data.id+'&n='+Math.random(),{},function(data){
						eval("data="+data);
						$('#view_${action_id}').form('load',data);
						var funcs = data["entity.funcsStr"].split(';');
						for(var i = 0;i<funcs.length;i++){
							var node = $('#view_${action_id}').find('#funcTree').tree('find',funcs[i]);
							if(node){
								$('#view_${action_id}').find('#funcTree').tree('check',node.target);
							}
						}
						$('#view_${action_id}').find('span.tree-checkbox').unbind().click(function(){return false;});
						//$('#view_${action_id}').find('span.tree-hit.tree-expanded').unbind().click(function(){return false;});
					});
					}
				});
			}
		});
	}
}


function delete_${action_id}(data) {
	$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getProperty('net.esj.background.message','bg.datagrid.delete.ask')}', function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/agency/group-delete.json',
				data:{id : data.id},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					$("#datagrid_${action_id}").datagrid('reload');
					$('#datagrid_${action_id}').datagrid('clearSelections');
				}
			});
		}
	});
}

function copy_${action_id}(data) {
	$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '确定要拷贝该权限组？', function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/agency/group-copyGroup.json',
				data:{id : data.id},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					$("#datagrid_${action_id}").datagrid('reload');
					$('#datagrid_${action_id}').datagrid('clearSelections');
				}
			});
		}
	});
}



</script>
<@operations contextUri='agency/group' />